import type { RequiredDeep } from 'type-fest'

import { ajax } from '@/utils'

import type { components } from '../schema'

/**
 * 鉴权接口
 */
export const authApi = {
  /**
   * 登录
   */
  login(data: ILoginReq): Promise<ILoginRes> {
    return ajax.post('/auth/login', data)
  },
  /**
   * 登出
   */
  logout() {
    return ajax.post('/auth/logout')
  },
  /**
   * 获取图形验证码
   */
  getCaptcha(): Promise<IGetCaptchaRes> {
    return ajax.get('/auth/captcha')
  }
}

export type ILoginReq = components['schemas']['LoginDTO']
export type ILoginRes = RequiredDeep<components['schemas']['LoginVO']['data']>
export type IGetCaptchaRes = Required<components['schemas']['CaptchaVO']>
